import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;


public class ReciprocalConnectionThread extends Thread {
    String hostName;
    int portNumber;
    Socket connectionToReceiver;
    String comingFromHostName;
    Socket connection;
    
    public ReciprocalConnectionThread(String host, int port, String comingFromHostName) {
            this.comingFromHostName = comingFromHostName;
            connectionToReceiver = connection;
            this.hostName = host;
            this.portNumber = port;
    }
    
    public void run() {
            try {
            		connectionToReceiver = new Socket(hostName, portNumber);
            		if(connectionToReceiver == null) {
            			System.out.println("Null connection in Reciprocal connection thread");
            			return;
            		}
            		System.out.println("In reciprocal connection thread, connecting to " + hostName + "  " + portNumber);
                    DataOutputStream dos = new DataOutputStream(connectionToReceiver.getOutputStream());
                    dos.writeInt(6);
                    dos.writeUTF(comingFromHostName);
                    connectionToReceiver.close();
           } catch (UnknownHostException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
            } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
            }
    }
}